package hotciv.view.tool;
import hotciv.framework.*;
import hotciv.view.GfxConstants;
import minidraw.framework.DrawingEditor;
import minidraw.standard.NullTool;
import java.awt.event.MouseEvent;

public class ActionTool extends NullTool 
{

	private Game game;
	private DrawingEditor editor;

	public ActionTool(DrawingEditor editor, Game game) 
	{
		this.editor = editor;
		this.game = game;
	}

	public void mouseDown(MouseEvent e, int x, int y) 
	{
		Position p = GfxConstants.getPositionFromXY(x, y);
		Unit unit = game.getUnitAt(p);

		if (e.isShiftDown() == true) 
		{
			if(game.getUnitAt(p).getTypeString() == GameConstants.SETTLER && game.getCityAt(p) == null && game.getUnitAt(p).getOwner() == game.getPlayerInTurn())
			{
				game.performUnitActionAt(p);
				editor.showStatus(game.getPlayerInTurn() + " created a new settlement!");
			}
			else if(game.getUnitAt(p).getTypeString() == GameConstants.ARCHER && game.getUnitAt(p).getOwner() == game.getPlayerInTurn())
			{
				game.performUnitActionAt(p);
				editor.showStatus(game.getPlayerInTurn() + " Archer has fortified!");
			}
			
			
			else if(game.getUnitAt(p).getTypeString() == GameConstants.FORTIFIED_ARCHER && game.getUnitAt(p).getOwner() == game.getPlayerInTurn())
			{
				game.performUnitActionAt(p);
				editor.showStatus(game.getPlayerInTurn() + " Archer has lessened its defenses!");
			}
			
			else if(game.getUnitAt(p) != null && game.getUnitAt(p).getOwner() != game.getPlayerInTurn())
				editor.showStatus("You cannot use an enemy's units!");
		}
	}	
}
